package com.backend.icpc.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

@RestController
public class Info {
    public ArrayList teams;

    public Team init_team(String s1, String s2, int c, int f){
        Team t = new Team();
        Random r = new Random();
        if(c == 1)
        {
            t.setIs_concerned(1);
        }
        if(f == 1)
        {
            t.setIs_form(1);
            t.setIs_star(0);
        }
        else {
            t.setIs_form(0);
            t.setIs_star(1);
        }
        int cnt = 0;
        int Fashi = 0;
        for(int i = 0; i < 4; i ++)
        {
            int ac = r.nextInt(4);
            if(ac <= 1)
            {
                switch(i){
                    case 0:{
                        t.set_acA(false);
                        break;
                    }
                    case 1:{
                        t.set_acB(false);
                        break;
                    }
                    case 2:{
                        t.set_acC(false);
                        break;
                    }
                    case 3:{
                        t.set_acD(false);
                        break;
                    }
                }
            }
            else {
                cnt ++;
                int timec = r.nextInt(100);
                Fashi += timec;
                switch(i){
                    case 0:{
                        t.setScA(timec);
                        break;
                    }
                    case 1:{
                        t.setScB(timec);
                        break;
                    }
                    case 2:{
                        t.setScC(timec);
                        break;
                    }
                    case 3:{
                        t.setScD(timec);
                        break;
                    }
                }
            }
        }
        t.setSname(s1);
        t.setTname(s2);
        t.setAc_cnt(cnt);
        t.setFashi(Fashi);
        return t;
    }

    @RequestMapping("/index/init/")
    public ArrayList spend_all()
    {
        teams = new ArrayList<>();
        Team a = init_team("聊城大学", "陈陈陈", 1, 1);
        Team b = init_team("聊城大学", "算法未来研究所", 1, 1);
        Team c = init_team("聊城大学","必然性",1,1);
        Team d = init_team("聊城大学","凌乱之风",1,1);
        Team e = init_team("山东大学","追光者", 1, 1);
        Team f = init_team("山东大学","樱之重生",0,1);
        Team g = init_team("山东大学","再交一发说不定ac",1,0);
        Team h = init_team("山东大学","动力老子",1,0);
        Team i = init_team("临沂大学","假如我一发就WA，阁下该如何应队",0,1);
        Team j = init_team("临沂大学","山理五队(涡轮增鸭)",1,1);
        Team k = init_team("临沂大学","We Rock!",1,0);
        Team l = init_team("临沂大学","她与银牌皆失",0,1);
        Team m = init_team("山东理工大学","你也不想ICPC连个铜都没有吧嘿嘿嘿",0,1);
        Team n = init_team("山东理工大学","翻斗花园突破手",0,0);
        Team o = init_team("山东理工大学","夏日少年梦",1,1);
        Team p = init_team("山东理工大学","芝士队名",1,1);
        Team q = init_team("中国海洋大学","外卖骑手战鹰",0,1);
        Team r = init_team("中国海洋大学","我们仍未知道那天WA的原因",0,0);
        Team s = init_team("中国海洋大学","失踪的天鹅之考研怎么你了",1,1);
        Team t = init_team("中国海洋大学","奥德赛号",0,1);
        teams.add(a);
        teams.add(b);
        teams.add(c);
        teams.add(d);
        teams.add(e);
        teams.add(f);
        teams.add(g);
        teams.add(h);
        teams.add(i);
        teams.add(j);
        teams.add(k);
        teams.add(l);
        teams.add(m);
        teams.add(n);
        teams.add(o);
        teams.add(p);
        teams.add(q);
        teams.add(r);
        teams.add(s);
        teams.add(t);
        Collections.sort(teams);
        return teams;
    }
    @RequestMapping("/index/init/teams/")
    public ArrayList spend_teams(){
        return teams;
    }

    @RequestMapping("/index/all/lcu/")
    public List<Team> spend_lcu()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getSname().equals("聊城大学")).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/lyu/")
    public List<Team> spend_lyu()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getSname().equals("临沂大学")).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/sdu/")
    public List<Team> spend_sdu()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getSname().equals("山东大学")).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/sdlgu/")
    public List<Team> spend_sdlgu()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getSname().equals("山东理工大学")).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/seau/")
    public List<Team> spend_seau()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getSname().equals("中国海洋大学")).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/concerned/")
    public List<Team> spend_concerned()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getIs_concerned() == 1).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/form/")
    public List<Team> form()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getIs_form() == 1).collect(Collectors.toList());
        return arr;
    }
    @RequestMapping("/index/all/star/")
    public List<Team> star()
    {
        List<Team> arr = teams;
        arr = arr.stream().filter(u -> u.getIs_star() == 1).collect(Collectors.toList());
        return arr;
    }

}
